package com.dlry.db;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.dlry.entity.DlMeetingRoom;
import com.dlry.entity.DlMeetingRoomBooking;

public interface MeetingRoomBookingRepository extends JpaRepository<DlMeetingRoomBooking, Long> {

	<S extends DlMeetingRoomBooking> long count(Example<S> arg0);

	<S extends DlMeetingRoomBooking> boolean exists(Example<S> arg0);

	<S extends DlMeetingRoomBooking> Page<S> findAll(Example<S> arg0, Pageable arg1);

	<S extends DlMeetingRoomBooking> S findOne(Example<S> arg0);

	Page<DlMeetingRoomBooking> findAll(Pageable arg0);

	long count();

	void delete(DlMeetingRoomBooking arg0);

	void delete(Iterable<? extends DlMeetingRoomBooking> arg0);

	void delete(Long arg0);

	void deleteAll();

	boolean exists(Long arg0);

	DlMeetingRoomBooking findOne(Long arg0);

	<S extends DlMeetingRoomBooking> S save(S arg0);

	List<DlMeetingRoomBooking> findAll();

	List<DlMeetingRoomBooking> findAll(Sort sort);

	List<DlMeetingRoomBooking> findAll(Iterable<Long> ids);

	<S extends DlMeetingRoomBooking> List<S> save(Iterable<S> entities);

	void flush();

	<S extends DlMeetingRoomBooking> S saveAndFlush(S entity);

	<S extends DlMeetingRoomBooking> List<S> findAll(Example<S> example);

	<S extends DlMeetingRoomBooking> List<S> findAll(Example<S> example, Sort sort);

	// 检测有没相冲突的会议
	@Query("from DlMeetingRoomBooking where endTime > ?1 and bookingTime < ?2 and room = ?3")
	DlMeetingRoomBooking validateBooking(Timestamp starttamp, Timestamp endtamp, DlMeetingRoom room);

	// 更新时检测有没相冲突的会议
	@Query("from DlMeetingRoomBooking where endTime > ?1 and bookingTime < ?2 and room = ?3 and id != ?4")
	DlMeetingRoomBooking validateBookingUpdate(Timestamp starttamp, Timestamp endtamp, DlMeetingRoom room, Long id);

}
